import { request } from '@/utils/request'
import type {
  User,
  CodeType,
  UserInfo,
  PatientList,
  Patient
} from '@/types/user'

// 密码登录接口
export const loginByPassword = (mobile: string, password: string) => {
  return request<User>('/login/password', 'POST', { mobile, password })
}

// 获取验证码接口
export const sendMobileCode = (mobile: string, type: CodeType) => {
  request('/code', 'GET', { mobile, type })
}

// 短信验证码登录
export const loginByMobile = (mobile: string, code: string) => {
  return request<User>('/login', 'POST', { mobile, code })
}

// 获取用户信息
export const getUserInfo = () => {
  return request<UserInfo>('/patient/myUser', 'GET')
}

// 获取患者信息列表
export const getPatientList = () => {
  return request<PatientList>('/patient/mylist')
}

// 添加患者接口

export const addPatient = function (patient: Patient) {
  console.log('patient:', patient)
  return request('/patient/add', 'POST', patient)
}

// 编辑患者的接口

export const editPatient = function (patient: Patient) {
  return request('/patient/update', 'PUT', patient)
}

// 删除患者的接口
export const delPatient = function (id: string) {
  // return request('/patient/del/' + id, 'DELETE')
  return request(`/patient/del/${id}`, 'DELETE')
}

// 查询患者详情
export const getPatientDetail = (id: string) =>
  request<Patient>(`/patient/info/${id}`)
